package com.example.demo.dao;

import com.example.demo.entity.UserInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import java.util.List;

@Slf4j
@Component
public class UserDao {

    @PersistenceContext
    private EntityManager entityManager;


    public List<UserInfo> getOlder(int age) {
        String sql = "SELECT * FROM user_info ui WHERE ui.age > :age ";
        Query q = entityManager.createNativeQuery(sql, UserInfo.class);
        q.setParameter("age", age);
        List res = q.getResultList();
        return res;
    }

}
